//
//  Car.m
//  Chapt11_CarProperties_v11-01
//
//  Created by Ronald Ram on 16/03/2011.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "Car.h"


#import "Engine.h"
#import "Tire.h"

@implementation Car

@synthesize name;
@synthesize engine;


-(id) init
{
    if (self = [super init]) 
    {
        self.name = @"Car"; //SAME AS: [self setName:@"Car"];
        tires = [[NSMutableArray alloc] init];
        
        for (int i=0; i<4; ++i) 
        {
            [tires addObject:[NSNull null] ];
        }
    }
    
    return (self);
}

-(void) dealloc
{
    self.name = nil; //SAME AS: [self setName:nil];
    [engine release];
    [tires release];
    
    [super dealloc];
}


-(void) setTire:(Tire *)tire atIndex:(int)index
{
    [ tires replaceObjectAtIndex:index withObject:tire ];
}

-(Tire *) tireAtIndex:(int)index
{
    return ( [tires objectAtIndex:index] );
}

-(void) print
{
    NSLog( @"Car Name = %@", [self name] );
    
    for (int i=0; i<4; ++i) 
    {
        NSLog(@"Tire [%d] = %@", i, [self tireAtIndex:i] );
    }
    
    NSLog(@"Engine = %@", [self engine] );
}

@end
